const { defineConfig } = require('@vue/cli-service')
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const productionGzipExtensions = ["js", "css"];

module.exports = defineConfig({
  transpileDependencies: true,
  productionSourceMap: false, //false:减少包大小，加密源码
  lintOnSave: false,
  assetsDir: "static",
  pluginOptions: {},
  configureWebpack: () => {
    if (process.env.NODE_ENV === "production") {
      return {
        plugins: [
          new CompressionWebpackPlugin({
            filename: "[path][base].gz", // 提示compression-webpack-plugin@2.0.0的话filename改为asset
            algorithm: "gzip",
            test: new RegExp(
              "\\.(" + productionGzipExtensions.join("|") + ")$"
            ),
            threshold: 10240, //内容超过10KB进行压缩
            minRatio: 0.8,
            deleteOriginalAssets: false,  //压缩后保留原文件
            // __VUE_I18N_FULL_INSTALL__: true,
            // __VUE_I18N_LEGACY_API__: false,
            // __VUE_I18N_PROD_DEVTOOLS__: false
          })
        ]
      };
    }
  },
  chainWebpack: config =>
    config.resolve.alias.set("vue-i18n", 'vue-i18n/dist/vue-i18n.cjs.js')
})
